
***************************************************************************************************************
/*
THIS DO-FILE:
Gets 2008 (wave 9) helper information from raw HRS data
*/
***************************************************************************************************************

clear
set more off
set maxvar 10000

***************************************************************************************************************
use "$rawdata\h08core\h08sta\H08G_R.DTA"
merge 1:m HHID PN using "$rawdata\h08core\h08sta\H08G_HP.DTA", keep(3)

egen LOPN=concat(LSUBHH OPN)

destring HHID, replace
destring PN, replace
gen double hhidpn=1000*HHID+PN

destring OPN, replace
destring LOPN, replace

gen double kidid=10000*HHID+LOPN
								   
*helper type
gen helper_spouse=inlist(LG069,2,26,27)
gen helper_child=inlist(LG069,3,4,5,6,7,8,28,30,31,90,91)
gen helper_othfam=inlist(LG069,9,10,11,12,13,14,15,16,17,18,19,33)
gen helper_nonfam=inlist(LG069,20,21,22,23,24,25)
foreach var in helper_spouse helper_nonfam helper_child helper_othfam {
	replace `var'=. if helper_spouse==0 & helper_nonfam==0 & helper_child==0 & helper_othfam==0
}
*0 out of 4678 are missing -- they won't be counted as helpers

*helper paid?
gen 	helper_paid=(LG076==1) if inlist(LG076,1,5) & helper_nonfam==1
replace helper_paid=1 if LG069==22						 
								 
*helper frequency - converted to days per month
gen 	helper_dpm=LG070 if LG070<=31  //reported days per month
replace helper_dpm=LG071*4 if LG071<=7 //reported days per week
replace helper_dpm=30 if LG072==1	   //reported every day
replace helper_dpm=0 if LG070==96 	   //not a helper last month
*impute the "DK" responses with median for that type of helper
forval x=2/91 {
	qui sum helper_dpm if LG069==`x', det
	qui replace helper_dpm=r(p50) if LG069==`x' & (inlist(LG070,98,99) | LG071==8 | LG072==8) & helper_dpm==.
}
qui sum helper_dpm, det
qui replace helper_dpm=r(p50) if (inlist(LG070,98,99) | LG071==8 | LG072==8) & helper_dpm==. //for the one without type of helper match

*helper hours per day
gen 	helper_hpd=LG073 if LG073<=24
*impute the "DK" responses by family/other and days per month categories
foreach var in helper_spouse helper_child helper_othfam helper_nonfam {
	sum helper_hpd if `var'==1 & helper_dpm>=1 & helper_dpm<=7, det
	replace helper_hpd=r(p50) if `var'==1 & helper_dpm>=1 & helper_dpm<=7 & inlist(LG073,98,99) & helper_hpd==.
	sum helper_hpd if `var'==1 & helper_dpm>=8 & helper_dpm<=27, det
	replace helper_hpd=r(p50) if `var'==1 & helper_dpm>=8 & helper_dpm<=27 & inlist(LG073,98,99) & helper_hpd==.	
	sum helper_hpd if `var'==1 & helper_dpm>=28 & helper_dpm<=31, det
	replace helper_hpd=r(p50) if `var'==1 & helper_dpm>=28 & helper_dpm<=31 & inlist(LG073,98,99) & helper_hpd==.
}

*hours per month
gen		helper_hpm=helper_hpd*helper_dpm
*those who report 0 or . dpm or hpd won't be counted as helpers unless AL/NH helper

*type of care
egen helper_fam=rowtotal(helper_spouse helper_child helper_othfam), missing
bys hhidpn: egen rec_inf=max(helper_fam)
bys hhidpn: egen rec_form=max(helper_nonfam)
bys hhidpn: egen rec_paid=max(helper_paid)

*hours - total over all of person's helpers
gen hrs_inf_temp=helper_hpm if helper_fam==1
bys hhidpn: egen hrs_inf=sum(hrs_inf_temp)
gen hrs_form_temp=helper_hpm if helper_nonfam==1
bys hhidpn: egen hrs_form=sum(hrs_form_temp)
egen hrs_total=rowtotal(hrs_inf hrs_form)

***************************************************************************************************************
*ADL AND IADL (including money) HELPERS (up to 7)
preserve
drop if LADLNDX==. & LIADLNDX==. & LMNYNDX==. 
keep hhidpn OPN LOPN kidid helper_hpm helper_spouse helper_child helper_othfam helper_nonfam helper_paid ///
	 rec_inf rec_form hrs_inf hrs_form hrs_total
foreach var in helper_hpm helper_spouse helper_child helper_othfam helper_nonfam helper_paid rec_inf rec_form hrs_inf hrs_form hrs_total {
	rename `var' `var'9
}
duplicates drop
save "allADLIADLhelpers_9.dta", replace
restore
***************************************************************************************************************
